#ifndef __PKG_UTIL_H__
#define __PKG_UTIL_H__

#include <sys/queue.h>


char *ns_strdup(const char *src);

void arg_rage_quit(const char *function, const char *message, int ret);

void _pkg_util_trim_newline(char *);
int _nsstrcmp(const void *, const void *);
int _qsstrcmp(const void *, const void *);
void _pkg_util_path_join(char *, const char *, const char *);
void _pkg_util_fp_copy(FILE *, FILE *);
void *pkg_calloc(size_t, size_t);

#define FLAG_CHECK(x, flags) \
        (x & flags)

/*
 * XXX: Make this set proper errors.
 */
#define CHECKMAGIC(type, chk, mag) \
        if (chk->magic != mag) { \
                printf("bad magic for %s in %s!", #type, __func__); \
                exit(-1); \
        }

#define REALLOCARRAY(array, sz, newsz, tmp) \
        tmp = array; \
        array = realloc(tmp, sizeof(*tmp) * newsz); \
        if (array == NULL) \
                array = tmp; \
        else \
                sz = newsz;

#define STR_MATCH(s1, s2) (strcmp(s1, s2) == 0)

#define STRMATCH(s1, s2)        STR_MATCH(s1, s2)

#endif
